package com.gitee.lw114514.webapp_memorandium.service.GetService.Impl;

import com.gitee.lw114514.webapp_memorandium.service.GetService.GetService;
import com.gitee.lw114514.webapp_memorandium.dao.TaskDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.gitee.lw114514.webapp_memorandium.pojo.Task;

import java.util.List;

@Service
public class GetServiceImpl implements GetService {
    @Autowired
    private TaskDao taskDao;

    @Override
    public List<Task> findAllCompleteTask() {
        // 1.调用dao层获取用户数据
        List<String> tasks =  taskDao.FindCompleteTask();

        // 2.将数据映射为Task对象
        List<Task> taskList = tasks.stream().map(task -> {
            String[] parts = task.split(",");
            Integer id = Integer.parseInt(parts[0]);
            String task_content = parts[1];
            String task_time = parts[2];
            Boolean task_status = Boolean.parseBoolean(parts[3]);
            return new Task(id, task_content, task_time, task_status);
        }).toList();

        // 返回结果
        return taskList;
    }

    @Override
    public List<Task> findAllUncompleteTask() {
        // 1.调用dao层获取用户数据
        List<String> tasks =  taskDao.FindUncompleteTask();

        // 2.将数据映射为Task对象
        List<Task> taskList = tasks.stream().map(task -> {
            String[] parts = task.split(",");
            Integer id = Integer.parseInt(parts[0]);
            String task_content = parts[1];
            String task_time = parts[2];
            Boolean task_status = Boolean.parseBoolean(parts[3]);
            return new Task(id, task_content, task_time, task_status);
        }).toList();

        // 3.返回结果
        return taskList;
    }
}
